<?php
namespace app\shop\model;

use app\BaseModel;
use think\facade\Db;
class IndexUser extends BaseModel
{
	//定义表名

	protected $name = 'longbing_card_user';
    /**
     * @param $dis
     * @return array|string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 获取用户信息
     */
	public function userInfo($dis){

        $data = $this
            ->alias('a')
            ->leftJoin('longbing_card_selling_profit b' ,'a.id = b.user_id')
            ->where($dis)
            ->field('a.*,b.profit')
            ->find();
        return !empty($data)?$data->toArray():$data;
    }

    /**
     * User: chenniang
     * Date: 2019-09-10 15:30
     * @param $dis
     * @return array|\think\Model|null
     * descption:获取用户信息
     */
    public function userInfos($dis){
	    $data = $this->where($dis)->find();
        return !empty($data)?$data->toArray():$data;
    }

    /**
     * @param $data
     * @return int|string
     * 编辑信息
     */
    public function userUpdate($dis,$data){
        $data['update_time'] = time();
        $res = $this->where($dis)->update($data);
        return $res;
    }

    /**
     * @param $dis
     * @return mixed
     * 获取用户头像
     */
    public function userImage($dis){
        $data = $this->where($dis)->value('avatarUrl');
        return $data;
    }


    /**
     * @param $dis
     * @return int
     * 获取人数
     */
    public function userCount($dis){
       $data = $this->where($dis)->count();
       return $data;
    }

    /**
     * @param $dis
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 人数
     */

    public function userSelect($dis){
        $data = $this->where($dis)->select()->toArray();
        return $data;
    }

    /**
     * @param $dis
     * @return array
     * @throws \think\exception\DbException
     * 合伙人
     *
     */
    public function partner($dis){
        $data = $this->where($dis)->order('create_money desc')->field('id,nickName,avatarUrl,create_time, create_money')->paginate(10)->toArray();
        return $data;
    }












}